package com.eugene.ui.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eugene.process.WriteCashFlow;
import com.eugene.ui.dialog.DialogColumnConfig;
import com.eugene.ui.util.IStructuredViewer;

import test.DialogXML;
import test.MyDialog;
import test.MyTestDialog;

public class OpenMyDialog extends AbstractHandler {
	private final static Logger logger = 
		LoggerFactory.getLogger(OpenMyDialog.class);
	
	private TableViewer tableViewer;

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbenchPage page = window.getActivePage();
		IWorkbenchPart part = page.getActivePart();

		if (part instanceof IStructuredViewer) {
			tableViewer = ((IStructuredViewer) part).getTableViewer();
		} else {
			MessageDialog.openInformation(window.getShell(), "Info",
					"There are no Columns in the active window");
		}

		// MyDialog dialog = new MyDialog(HandlerUtil.getActiveWorkbenchWindow(
		// event).getShell());
		// MyTestDialog dialog = new
		// MyTestDialog(HandlerUtil.getActiveWorkbenchWindow(
		// event).getShell());
		
//		DialogColumnConfig dialog = new DialogColumnConfig(HandlerUtil.getActiveWorkbenchWindow(
//				event).getShell());
		DialogColumnConfig dialog = new DialogColumnConfig(HandlerUtil.getActiveWorkbenchWindow(
				event).getShell(),tableViewer);
		dialog.create();

		if (dialog.open() == Window.OK) {
			logger.debug("zzz:{}",dialog.getTableViewer().getTable().getColumnCount());
			// System.out.println(dialog.getFirstName());
			// System.out.println(dialog.getLastName());
		}

		return null;

	}

}
